/*============================================================================
  Ajax Cart
  Built with Sass - http://sass-lang.com/

  Some things to know about this file:
    - This file uses the same grid as default.scss.liquid.
      - If you want to use this separately, please include the following sections from default.scss.liquid:
        * #Breakpoint and Grid Variables
        * #Grid Setup
      - You may need to massage the code so it doesn't reference any non-existent mixins.

  This file includes
    - Sass helpers
    - Colour variables to customize
    - Styles for cart drawer, modal, and the flipped add to cart button
==============================================================================*/

/*============================================================================
  #Breakpoint and Grid Variables (from default.scss.liquid)
==============================================================================*/
$viewportIncrement: 1px;

$small: 480px;
$medium: 768px;
$large: 769px;

$postSmall: $small + $viewportIncrement;
$preMedium: $medium - $viewportIncrement;
$preLarge: $large - $viewportIncrement;

$gutter: 24px;

/*============================================================================
  Ajaxify Colours
  Add your theme colors in here, or create new styles.
    - If creating new styles, you may have to restyle text, headers and links
==============================================================================*/
$colorBody: {{ settings.color_body_bg }};
$colorTextBody: {{ settings.color_body_text }};
$colorBorder: {{ settings.color_borders }};

/*============================================================================
  Dependency-free breakpoint mixin
// http://blog.grayghostvisuals.com/sass/sass-media-query-mixin/
==============================================================================*/
$min: min-width;
$max: max-width;
@mixin at-query ($constraint, $viewport1, $viewport2:null) {
  @if $constraint == $min {
    @media screen and ($min: $viewport1) {
      @content;
    }
  } @else if $constraint == $max {
    @media screen and ($max: $viewport1) {
      @content;
    }
  } @else {
    @media screen and ($min: $viewport1) and ($max: $viewport2) {
      @content;
    }
  }
}

/*============================================================================
  Sass Helpers
==============================================================================*/
@mixin prefix($property, $value) {
  -webkit-#{$property}: #{$value};
  -moz-#{$property}: #{$value};
  -ms-#{$property}: #{$value};
  -o-#{$property}: #{$value};
  #{$property}: #{$value};
}

@mixin transform-origin($origin) {
  @include prefix('transform-origin', #{$origin});
}

@mixin transform-style($style: preserve-3d) {
  @include prefix('transform-style', #{$style});
}

@mixin perspective($perspective) {
  @include prefix('perspective', #{$perspective});
}

@mixin backface($visibility: hidden) {
  @include prefix('backface-visibility', #{$visibility});
}

@mixin box-sizing($box-sizing: border-box) {
  -webkit-box-sizing: #{$box-sizing};
  -moz-box-sizing: #{$box-sizing};
  box-sizing: #{$box-sizing};
}

@mixin transform($transform) {
  @include prefix('transform', #{$transform});
}

@mixin transition($transition: 0.1s all) {
  @include prefix('transition', #{$transition});
}

@mixin clearfix() {
  &:after {
    content: "";
    display: table;
    clear: both;
  }
}

@function color-control($color) {
  @if (lightness( $color ) > 40) {
    @return #000;
  }
  @else {
    @return #fff;
  }
}

/*============================================================================
  General Styles
==============================================================================*/
@include at-query ($max, $small) {
  body.ajaxify-modal--visible {
    overflow: hidden;
  }
}

.ajaxifyCart-loader {
  display: none;
  opacity: 0;
  position: absolute;
  right: -24px;
  top: 50%;
  margin-top: -5px;
  padding: 0;
  width: 16px;
  height: 16px;
  @include transition(opacity 0.1s);
  background-repeat: no-repeat;
  background-image: url();

  .flip--is-loading & {
    display: block;
    opacity: 1;
  }
}

form[action="/cart/add"],
form[action^="/cart/add"] {
  @include clearfix;
}


/*============================================================================
  Ajaxify Cart - General
==============================================================================*/
.ajaxifyCart--content {
  position: relative;
  background-color: $colorBody;
  @include perspective(1000px);
  @include transform-style(preserve-3d);
  @include transition(all 450ms cubic-bezier(0.57,.06,.05,.95));
  padding-top: $gutter;
  padding-bottom: $gutter;
  overflow: hidden;

  .is-visible & {
    @include transition(all 550ms cubic-bezier(0.57, 0.06, 0.05, 0.95));
  }

  form {
    margin-bottom: 0;
  }

  @include at-query ($max, $medium) {
    padding-top: 15px;
    padding-bottom: 15px;
  }
}

// Row and column spacing
.ajaxifyCart--products {
  padding-bottom: 10px;
  margin-bottom: 20px;
}

.ajaxifyCart--product {
  position: relative;
  padding: 10px 0;

  &:first-child {
    padding-top: 0;
  }
}

.ajaxifyCart--product,
.cart-row {
  @include transform-origin(top);
  @include transition(all 650ms cubic-bezier(0.57, 0.06, 0.05, 0.95));
  @include transform('rotateX(0deg)');
  max-height: 500px;
  visibility: visible;

  &.is-removed {
    overflow: hidden;
    opacity: 0;
    padding: 0;
    margin: -$gutter 0 0;
    visibility: hidden;
    @include transform('rotateX(-92deg)');
    @include backface(hidden);
    @include transition(all 450ms cubic-bezier(0.57,.06,.05,.95));
    max-height: 0;
  }
}

.ajaxifyCart--row {
  clear: both;
  @include clearfix;
}

.ajaxCart--product-image {
  display: block;
  overflow: hidden;
  margin-bottom: 15px;

  img {
    display: block;
    margin: 0 auto;
    max-width: 100%;
  }
}


/*============================================================================
  #Quantity Selectors
==============================================================================*/
.js-qty {
  position: relative;
  margin-bottom: 1em;
  max-width: 100px;
  min-width: 75px;
  overflow: visible;
  @include backface(hidden);

  input[type="text"] {
    display: block;
    background: none;
    text-align: center;
    width: 100%;
    padding: 5px 25px;
    margin: 0;
  }
}

.js--qty-adjuster {
  cursor: pointer;
  position: absolute;
  display: block;
  top: 0;
  bottom: 0;
  padding: 5px 0;
  width: 20px;
  text-align: center;
  overflow: hidden;
  -webkit-user-select: none;
  -moz-user-select:    none;
  -ms-user-select:     none;
  -o-user-select:      none;
  user-select:         none;
  @include transition(all 0.2s ease-out);

  &:hover {
    background-color: $colorBorder;
  }

  &:active {
    background-color: darken($colorBorder, 10%);
  }
}

.js--add {
  right: 0;
  border-left: 1px solid $colorBorder;
}

.js--minus {
  left: 0;
  border-right: 1px solid $colorBorder;
}

/*============================================================================
  #Quantity Selectors in the Ajax Cart
==============================================================================*/
.ajaxifyCart--qty {
  @extend .js-qty;
  margin: 0;

  .ajaxifyCart--is-loading & {
    opacity: 0.5;
    @include transition(none);
  }
}

.ajaxifyCart--num {
  @include transition(all 0.1s ease-out);

  .supports-no-touch & {
    border: 1px solid rgba(0,0,0,0);
  }

  .cart-row:hover &,
  .ajaxifyCart--product:hover &,
  .supports-touch & {
    border-color: $colorBorder;
  }
}

.ajaxifyCart--qty-adjuster {
  @extend .js--qty-adjuster;
  opacity: 0;

  .cart-row:hover &,
  .ajaxifyCart--product:hover &,
  .supports-touch & {
    opacity: 1;
    @include transition(background-color 0.2s ease-out);
  }

  // Turn off animation on initial hover
  .ajaxifyCart--product:hover &:hover {
    @include transition(none);
  }
}

.ajaxifyCart--add {
  @extend .js--add;
}

.ajaxifyCart--minus {
  @extend .js--minus;
}


/*============================================================================
  Ajaxify Flip
==============================================================================*/
.flip {
  display: block;
  float: left;
  position: relative;
  @include perspective(600px);
}

.flip-front,
.flip-back {
  @include transform-style(preserve-3d);
  @include transition(all 0.3s);
  @include backface(hidden);
  overflow: hidden;

  position: relative;
  z-index: 10;

  &:focus {
    outline: 0 none;
  }
}

.flip-front {
  @include transform-origin(100% 0);

  .is-flipped & {
    @include transform('rotateX(92deg) translateY(-50%)');
  }
}

.flip-back {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  opacity: 0;
  text-align: center;
  background-color: #464646;
  @include box-sizing();
  @include transform('rotateX(-90deg) translateY(50%)');
  @include transform-origin(0 100%);

  .is-flipped & {
    opacity: 1;
    @include transform('rotateX(0deg)');
  }
}

// Backup for no transforms
.flip.no-transforms {
  .flip-back {
    display: none;
  }

  &.is-flipped {
    .flip-back {
      display: block;
    }
  }
}

.flip-extra {
  display: inline;
  position: relative;
  padding: 2px 10px;
  opacity: 0;
  visibility: hidden;
  overflow: visible;
  white-space: nowrap;
  z-index: 5;
  top: 4px;
  line-height: 34px;
  @include transition(opacity 450ms cubic-bezier(0.57,.06,.05,.95));

  .is-flipped + & {
    opacity: 1;
    visibility: visible;
    @include transition(opacity 650ms cubic-bezier(0.57, 0.06, 0.05, 0.95) 750ms);
  }
}

.flip-cart {
  display: inline-block;
  padding: 0 8px;
}

.flip-checkout {
  margin: 0;
}


/*============================================================================
  Ajaxify Modal
==============================================================================*/
.ajaxify-modal {
  position: absolute;
  top: 170px;
  left: -200%;
  margin-left: -500px; // overridden with JS
  width: 100%;
  max-width: 760px;
  height: auto;
  z-index: 99999999;
  visibility: hidden;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  @include transition('left 0s linear 700ms, box-shadow 600ms cubic-bezier(0.47, 0.5, 0, 0.95) 400ms, margin-top 200ms ease-in-out');

  // Short screens
  @media only screen and (max-height:645px) {
    top: 70px;
  }

  // Medium-down screens
  @include at-query ($max, $medium) {
    max-width: 90%;
  }

  // Small screens
  @include at-query ($max, $small) {
    position: fixed;
    top: 0;
    bottom: 0;
    margin: 0!important;
    max-height: none;
    max-width: none;
  }

  .ajaxifyCart--content {
    padding-left: $gutter;
    padding-right: $gutter;

    // Medium-down screens
    @include at-query ($max, $medium) {
      padding-left: 15px;
      padding-right: 15px;
    }

    // Small screens
    @include at-query ($max, $small) {
      padding-bottom: 60px;
      min-height: 100%;
    }
  }

  &.is-visible {
    visibility: visible;
    left: 50%;
    @include transition('left 0s linear, box-shadow 600ms cubic-bezier(0.47, 0.5, 0, 0.95) 400ms, margin-top 200ms ease-in-out');

    // Large screens
    @include at-query ($min, $large) {
      box-shadow: 0px 10px 80px rgba(0,0,0,.25);
    }

    // Small screens
    @include at-query ($max, $small) {
      left: 0;
    }
  }

  .ajaxifyCart--row {

    & > div {
      padding-left: 20px;

      &:first-child {
        padding-left: 0;
      }
    }
  }

  .ajaxifyCart--product {
    @include transform(none);
  }

  .update-cart {
    display: none!important;
  }

  // No transform fallback
  &.no-transforms {
    border: 1px solid $colorBorder;
  }

}

#ajaxifyCart-overlay {
  position: fixed;
  width: 100%;
  height: 100%;
  visibility: hidden;
  top: 0;
  left: 0;
  z-index: 99999998;
  opacity: 0;
  cursor: pointer;
  @include transition(all 450ms cubic-bezier(0.57,.06,.05,.95));
  @if (lightness( $colorBody ) > 40) {
    background-color: #d3d3d3;
  }
  @else {
    background-color: #333333;
  }
}

@include at-query ($min, $postSmall) {
  .is-visible ~ #ajaxifyCart-overlay {
    visibility: visible;
    @include transition(all 650ms cubic-bezier(0.57, 0.06, 0.05, 0.95));
    @if (lightness( $colorBody ) > 40) {
      opacity: 0.8;
    }
    @else {
      opacity: 0.95;
    }

    .lt-ie9 & {
      -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
    }
  }
}

// Modal content transition
.ajaxify-modal .ajaxifyCart--content {
  @include transform(scale(0.9));
  opacity: 0;
}

.ajaxify-modal.is-visible .ajaxifyCart--content {
  @include transform(scale(1));
  opacity: 1;
}

// Quantity selector colors in the modal
// TO DO
.ajaxify-modal {

  // Small screen quantity appearance
  @include at-query ($max, $medium) {
    input[type="text"] {
      border-color: $colorBorder;
    }

    .ajaxifyCart--qty-adjuster {
      opacity: 1;
    }
  }
}

/*============================================================================
  Ajaxify Drawer
==============================================================================*/
.ajaxify-drawer {
  height: 0px;
  overflow: hidden;
  border-bottom: 0px solid transparent;
  @include perspective (1000px);
  @include transform-style(preserve-3d);
  @include transition(all 600ms cubic-bezier(0.47, 0.5, 0, 0.95));

  &.is-visible {
    @include transition(all 550ms cubic-bezier(0.47, 0, 0, 0.95));
    border-bottom: 1px solid $colorBorder;
  }

  .update-cart {
    display: none!important;
  }

  .ajaxifyCart--content {
    margin: 0 auto;
    opacity: 0;
    overflow: hidden;
    padding-top: $gutter;
    padding-bottom: $gutter;
    @include transform-origin(top);
    @include transform('rotateX(-90deg)');
  }

  &.is-visible .ajaxifyCart--content {
    opacity: 1;
    @include transform('rotateX(0deg)');
  }
}

.ajaxifyDrawer-caret {
  position: relative;
  display: block;
  height: 0;
  opacity: 0;
  overflow: hidden;

  .is-visible + & {
    opacity: 1;
    overflow: visible;
  }

  & > span {
    position: absolute;
    top: 0;
    left: 100%;
    display: block;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid $colorBody;
    margin-left: -6px;
    opacity: 0;
    @include transform(translate(0,-12px));
    @include transition(all 0.25s ease-in-out 0.2s);
  }

  .is-visible + & > span {
    @include transform(translate(0,0));
    opacity: 1;
  }
}



/*============================================================================
  Sprites
//   - using data URIs to prevent any additional http requests
==============================================================================*/
.sprite {
  display: block;
  text-indent: -9999px;
  background-repeat: no-repeat;
  background-position: 0 0;
}

.ajaxifyCart--add {
  @extend .sprite;
  background-position: center center;
  background-image: url();
}

.ajaxifyCart--minus {
  @extend .sprite;
  background-position: center center;
  background-image: url();
}

.ajaxifyCart--close {
  @extend .sprite;
  position: absolute;
  top: 20px;
  right: 20px;
  opacity: 0;
  visibility: hidden;
  border: 0 none;
  width: 30px;
  height: 25px;
  cursor: pointer;
  background: {
    color: transparent;
    position: center center;
    image: url()
  }
  z-index: 999999999;
  @include transition(all 450ms cubic-bezier(0.57,.06,.05,.95));

  .is-visible & {
    opacity: 0.8;
    visibility: visible;
    @include transition(opacity 650ms cubic-bezier(0.57, 0.06, 0.05, 0.95) 200ms);
  }

  &:hover {
    opacity: 1;
  }
}


@media
(-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {

  .ajaxifyCart--add {
    background-size: 8px;
    background-image: url();
  }

  .ajaxifyCart--minus {
    background-size: 8px;
    background-image: url();
  }

}
